<template>
  <div class="region">
    <div class="content">
      <div class="left">地区:</div>
      <ul>
        <li :class="{active:RegionFlag==''}" @click="changeRegion('')">全部</li>
        <li v-for="item in RegionArr" :class="{active:RegionFlag==item.value}" :key="item.value" @click="changeRegion(item.value)">{{ item.name }}</li>
      </ul>
    </div>
    
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from "vue";
import { reqHospitalLevelAndRegion } from "../../../api/home";
import type {
  HospitalLevelAndRegionResponseData,
  HospitalLevelAndRegionArr,
} from "../../../api/home/type";

// 存储地区的数据
let RegionArr = ref<HospitalLevelAndRegionArr>([])
// 地区高亮响应式数据
let RegionFlag = ref<string>('')
// 地区组件挂载完毕
onMounted(() => {
  getRegion();
});
// 获取医院地区的数据
const getRegion = async () => {
  let result: HospitalLevelAndRegionResponseData =
    await reqHospitalLevelAndRegion("Beijin");
  if (result.code == 200) {
    RegionArr.value = result.data;
  }
};

// 点击不同区域按钮回调
const changeRegion = (region:string)=>{
  RegionFlag.value = region
  //将医院地区参数回传给父组件
  $emit('getRegion',region)
}

let $emit = defineEmits(['getRegion'])

</script>

<style scoped lang="scss">
.region{
  color: #7f7f7f;
  margin-top: 10px;
  .content{
    display: flex;
    .left{
      margin-right: 10px;
      width: 45.4px;
    }
    ul{
      display: flex;
      flex-wrap: wrap; //换行
      li{
        margin: 0 10px 10px 0;
        &.active{
          color: #55a6fe;
        }
      }
      li:hover{
        color: #55a6fe;
        cursor: pointer;
      }
    }
  }
}

</style>